﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using AimGameLibrary;

namespace AimGameLibrary.GameObject
{
    public class Image2D : BaseGameObject
    {
        
        protected SpriteBatch spritebatch;
        protected Texture2D mytexture2d;
        protected Camera camera;
        bool Visible;
        public bool VisiblE { get { return Visible; } set { Visible = value; } }

        public Image2D(SpriteBatch inputspritebatch,Camera inputcamera)
        {
            Visible = true;

            this.spritebatch = inputspritebatch;
            this.camera = inputcamera;

            /// Set Defult
            MyViewData = new ViewData();
            MyViewData.Source = Rectangle.Empty;
            MyViewData.Colors = Color.White;
            MyViewData.Origin = Vector2.Zero;
            MyViewData.Scale = Vector2.One;
            MyViewData.Spriteeffects = SpriteEffects.None;
            MyViewData.Depth = 0.5f;
            
        }

        public Texture2D MyTexture2D { get { return mytexture2d; } set { mytexture2d = value; } }
        public virtual void SetupSourceAndTexture(Texture2D inputTexture)
        {
            this.MyTexture2D = inputTexture;
            MyViewData.Source = new Rectangle(0, 0, MyTexture2D.Width, MyTexture2D.Height);
        }

        #region IEditorDraw Members

        public override void Draw()
        {
            base.Draw();
            if (Visible)
                SubDraw();
        }

        protected virtual void SubDraw()
        {
            if(mytexture2d != null)
            /// DefultDraw | 1 sprite | Applycamera | SpriteEffect.None | Scale Apply to Position

            spritebatch.Draw(this.mytexture2d
                                    , this.camera.ApplyPosition(this)
                                    , MyViewData.Source
                                    , MyViewData.Colors
                                    , MyViewData.Rotation
                                    , MyViewData.Origin
                                    , MyViewData.Scale
                                    , MyViewData.Spriteeffects
                                    , MyViewData.Depth);
        }

        #endregion
    }
}
